home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 52.7 KB | 1,727 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UDragDrop.cp
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #if qDrag
-
- #ifndef __UDRAGDROP__
- #include "UDragDrop.h"
- #endif
-
- // MacApp
-
- #ifndef __UAPPLICATION__
- // #include "UApplication.h"
- #endif
-
- #ifndef __UAPPLEEVENTS__
- #include "UAppleEvents.h"
- #endif
-
- #ifndef __UBUSYCURSOR__
- #include "UBusyCursor.h"
- #endif
-
- #if qContainer
- #ifndef __UCONTAINER__
- #include "UContainer.h"
- #endif
- #endif
-
- #ifndef __UCOREGLOBALS__
- #include "UCoreGlobals.h"
- #endif
-
- #ifndef __UCOREUTILITIES__
- #include "UCoreUtilities.h"
- #endif
-
- #ifndef __UDISPATCHER__
- #include "UDispatcher.h"
- #endif
-
- #ifndef __UDRAGDROPBEHAVIOR__
- #include "UDragDropBehavior.h"
- #endif
-
- #ifndef __ULIST__
- #include "UList.h"
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __USCROLLER__
- #include "UScroller.h"
- #endif
-
- #ifndef __UUNDO__
- #include "UUndo.h"
- #endif
-
- #ifndef __UVIEW__
- #include "UView.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- // CALib
-
- #if qContainer
- #ifndef _CALIB_
- #include "CALib.h"
- #endif
- #endif
-
- // Toolbox
-
- #if qPowerPC || qModelCFM
- #ifndef __CODEFRAGMENTS__
- #include <CodeFragments.h>
- #endif
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __FOLDERS__
- #include <Folders.h>
- #endif
-
- #if qPowerPC || qModelCFM
- #ifndef __FRAGLOAD__
- #include <FragLoad.h>
- #endif
- #endif
-
- //========================================================================================
- // Globals
- //========================================================================================
-
- // public globals
- TDragDropSession* TDragDropSession::fgDragDropSession;
-
- // private globals
- DragTrackingHandlerUPP TDragDropSession::fDragTrackingHandlerUPP;
- DragReceiveHandlerUPP TDragDropSession::fDragReceiveHandlerUPP;
- DragSendDataUPP TDragDropSession::fDragSendDataUPP;
-
- #if qDebug
- short TDragFlavorStream::fInstanceCount; // initialize static refcount of TDragFlavorStreams
- #endif // qDebug
-
- //----------------------------------------------------------------------------------------
- // InitUDragManager
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void InitUDragManager()
- {
- if (!HasDragManager()) // balk if drag manager isn't present
- {
- #if qDebug
- ProgramBreak("InitUDragManager called but Drag Manager isn't present.");
- #endif
- return;
- }
-
- TDragDropSession::fgDragDropSession = new TDragDropSession;
- TDragDropSession::fgDragDropSession->IDragDropSession();
-
- // Force MADragRes jump table to be initialized. Necessary for compatibility
- // with AOCE. Subclasses of TDragDropSession MUST make this call.
- InitializeResidentDragSegment();
-
- MA_REGISTER_SIGNATURE(TDragDropBehavior, kDragDropBehavior);
- } // InitUDragManager
-
- //----------------------------------------------------------------------------------------
- // InitializeResidentDragSegment:Force MADragRes jump table to be initialized.
- // Necessary for compatibility with AOCE. Subclasses of TDragDropSession MUST call
- // this function once at startup.
- //----------------------------------------------------------------------------------------
- #pragma segment MADragRes
-
- void InitializeResidentDragSegment()
- {
- // nothing to do. calling this function forces the segment loader to initialize
- // the MADragRes segment's jump table.
- return;
- }
-
- //========================================================================================
- // CLASS TDragDropSession
- //========================================================================================
- #undef Inherited
- #define Inherited TObject
-
- #pragma segment MADragRes
- MA_DEFINE_CLASS_M1(TDragDropSession, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession constructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- TDragDropSession::TDragDropSession()
- : fDropTarget(NULL),
- fDragSource(NULL),
- fScroller(NULL),
- fSourceWindow(NULL),
- fTargetWindow(NULL),
- fDragItemList(NULL),
- fDragReference(0L),
- fDragLeftSourceView(FALSE),
- fTargetIsHilited(FALSE),
- fUserRequestedCopy(FALSE)
- {
-
- } // TDragDropSession::TDragDropSession
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::IDragDropSession
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragDropSession::IDragDropSession()
- {
- this->IObject();
-
- fDragItemList = new TDragItemList;
- fDragItemList->IDragItemList();
-
- // create universal proc pointers for the callbacks
- if (fDragTrackingHandlerUPP == NULL)
- fDragTrackingHandlerUPP = NewDragTrackingHandlerProc(TDragDropSession::DragTrackingHandlerGlue);
- FailNIL(fDragTrackingHandlerUPP);
- if (fDragReceiveHandlerUPP == NULL)
- fDragReceiveHandlerUPP = NewDragReceiveHandlerProc(TDragDropSession::DragReceiveHandlerGlue);
- FailNIL(fDragReceiveHandlerUPP);
- if (fDragSendDataUPP == NULL)
- fDragSendDataUPP = NewDragSendDataProc(TDragDropSession::DragSendDataProcGlue);
- FailNIL(fDragSendDataUPP);
- } // TDragDropSession::IDragDropSession
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::~DragDropSession
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- TDragDropSession::~TDragDropSession()
- {
- fDragItemList = (TDragItemList *)FreeIfObject(fDragItemList);
- } // TDragDropSession::~DragDropSession
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::DragTrackingHandlerGlue
- //----------------------------------------------------------------------------------------
- #pragma segment MADragRes
-
- pascal OSErr TDragDropSession::DragTrackingHandlerGlue(DragTrackingMessage message,
- WindowRef theWindowMgrWindow,
- void* handlerRefCon,
- DragReference theDragRef)
- {
- #if qSegments
- // Set and restore A5 for compatibility with AOCE
- long A5RegisterOnEntry = SetCurrentA5();
- #endif
- MAVolatileInit(OSErr, err, noErr);
-
- // scoped for destruction of Metrowerks destruction chain before restoring A5
- {
-
- // it is necessary for a failure handler to exist at this level to prevent
- // blowing away the failure handler stack while in drag manager callbacks
- FailInfo fi;
- Try(fi)
- {
- fgDragDropSession->DragTrackingHandler(message, theWindowMgrWindow,
- handlerRefCon, theDragRef);
- fi.Success();
- }
- else // Recover
- {
- err = fi.error; // don't resignal - we're in a callback
- }
- }
- #if qSegments
- SetA5(A5RegisterOnEntry);
- #endif
- return err;
- } // TDragDropSession::DragTrackingHandlerGlue
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::DragReceiveHandlerGlue
- //----------------------------------------------------------------------------------------
- #pragma segment MADragRes
-
- pascal OSErr TDragDropSession::DragReceiveHandlerGlue(WindowRef theWindowMgrWindow,
- void* handlerRefCon,
- DragReference theDragRef)
- {
- #if qSegments
- // Set and restore A5 for compatibility with AOCE
- long A5RegisterOnEntry = SetCurrentA5();
- #endif
- MAVolatileInit(OSErr, err, noErr);
- // scoped for destruction of Metrowerks destruction chain before restoring A5
- {
- // it is necessary for a failure handler to exist at this level to prevent
- // blowing away the failure handler stack while in drag manager callbacks
- FailInfo fi;
- Try(fi)
- {
- err = fgDragDropSession->DragReceiveHandler(theWindowMgrWindow,
- handlerRefCon, theDragRef);
- fi.Success();
- }
- else // Recover
- {
- err = fi.error; // don't resignal - we're in a callback
- }
-
- #if qDebug
- TDragFlavorStream::CheckInstanceCount(); // test the TDragFlavorStream instance count
- #endif
- }
- #if qSegments
- SetA5(A5RegisterOnEntry);
- #endif
- return err;
- } // TDragDropSession::DragReceiveHandlerGlue
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::DragSendDataProcGlue
- //----------------------------------------------------------------------------------------
- #pragma segment MADragRes
-
- pascal OSErr TDragDropSession::DragSendDataProcGlue(FlavorType theType,
- void* dragSendDataRefCon,
- ItemReference theItemRef,
- DragReference theDragRef)
- {
- #if qSegments
- // Set and restore A5 for compatibility with AOCE
- long A5RegisterOnEntry = SetCurrentA5();
- #endif
- MAVolatileInit(OSErr, err, noErr);
-
- // scoped for destruction of Metrowerks destruction chain before restoring A5
- {
-
- // it is necessary for a failure handler to exist at this level to prevent
- // blowing away the failure handler stack while in drag manager callbacks
- FailInfo fi;
- Try(fi)
- {
- fgDragDropSession->DragSendDataProc(theType, dragSendDataRefCon, theItemRef,
- theDragRef);
- fi.Success();
- }
- else // Recover
- {
- err = fi.error; // don't resignal
- }
- }
- #if qSegments
- SetA5(A5RegisterOnEntry);
- #endif
- return err;
- } // TDragDropSession::DragSendDataGlue
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::DragTrackingHandler
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragDropSession::DragTrackingHandler(DragTrackingMessage message,
- WindowRef /*theWindowMgrWindow*/,
- void* handlerRefCon,
- DragReference theDragRef)
- {
- fDragReference = theDragRef;
-
- switch (message)
- {
- case dragTrackingEnterHandler:
- this->HandleEnterHandler();
- break;
-
- case dragTrackingLeaveHandler:
- this->HandleLeaveHandler();
- break;
-
- case dragTrackingEnterWindow:
- this->HandleEnterWindow((TWindow *)handlerRefCon);
- break;
-
- case dragTrackingLeaveWindow:
- this->HandleLeaveWindow();
- break;
-
- case dragTrackingInWindow:
- this->HandleTrackInWindow();
- break;
-
- default:
- break;
- }
- return;
- } // TDragDropSession::DragTrackingHandler
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::DragReceiveHandler
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- OSErr TDragDropSession::DragReceiveHandler(WindowRef /*theWindowMgrWindow*/,
- void* /*handlerRefCon*/,
- DragReference theDragRef)
- {
- CTempDesc dropLocationDesc;
- TCommand* sourceCommand = NULL;
- TCommand* targetCommand = NULL;
- OSErr returnValue;
-
- if (!fDropTarget) // if no current target exists, return immediately
- return dragNotAcceptedErr;
-
- if (fDropTarget->DoMakeDropLocationDescriptor(dropLocationDesc))
- SetDropLocation(theDragRef, dropLocationDesc);
-
- CDragItemIterator dragItemIterator(fDragItemList);
-
- if (fDragSource && !this->UserRequestedCopy() && fDragSource->WillDragMove(fDropTarget))
- {
- if (fDragSource == fDropTarget)
- targetCommand = fDragSource->DoMakeDragDropCommand(cDragMove, dragItemIterator);
- else
- {
- sourceCommand = fDragSource->DoMakeDragDropCommand(cDrag, dragItemIterator);
- sourceCommand->fIdentifier = cDragMove;
-
- dragItemIterator.Reset(); // reset the iterator
- targetCommand = fDropTarget->DoMakeDragDropCommand(cDrop, dragItemIterator);
- targetCommand->fIdentifier = cDragMove;
- }
- }
- else
- targetCommand = fDropTarget->DoMakeDragDropCommand(cDrop, dragItemIterator);
-
- if (targetCommand) // should always have a target command
- {
- if (sourceCommand)
- //{
- // sourceCommand->LinkToSecondary(targetCommand); // link the commands
- sourceCommand->fContext->PostCommand(sourceCommand); // source command is primary
- //}
- //else
-
- targetCommand->fContext->PostCommand(targetCommand); // target command is primary
-
- // if this process is in the background, it is possible for
- // it to be sitting in WaitNextEvent with an infinite sleep value.
- // waking the process will cause the command(s) that were just posted
- // to be processed immediately.
- if (!gDispatcher->IsFrontProcess())
- gDispatcher->WakeProcess();
-
- if (!fDragSource)
- {
- TInvalCursorCommand *cursorCommand = new TInvalCursorCommand;
- cursorCommand->IInvalCursorCommand();
- gDispatcher->PostCommand(cursorCommand);
- }
-
- returnValue = noErr;
- }
- else
- {
- returnValue = dragNotAcceptedErr;
- #if qDebug
- // its an error if a source command was provided without a target
- if (sourceCommand)
- {
- ProgramBreak("###Drag source provided a target, drop target did not.");
- sourceCommand = (TCommand*)FreeIfObject(sourceCommand);
- }
- #endif
- }
-
- this->SetDropTarget(NULL); // allow the view to clean up
- fUserRequestedCopy = FALSE; // reset user request for copy
-
- return returnValue;
- } // TDragDropSession::DragReceiveHandler
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::DragSendDataProc
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragDropSession::DragSendDataProc(FlavorType theType,
- void* /*dragSendDataRefCon*/,
- ItemReference theItemRef,
- DragReference
- #if qDebug
- theDragRef
- #endif
- )
- {
- TDragItem *promisedItem = NULL;
-
- #if qDebug
- if (theDragRef != fDragReference)
- ProgramBreak("###DragSendDataProc called with mismatched Drag Reference");
- #endif
-
- promisedItem = new TDragItem(theItemRef);
- promisedItem->IDragItem();
- promisedItem->FocusOnFlavor(theType);
-
- fDragSource->DoFulfillPromise(promisedItem);
-
- FreeIfObject(promisedItem);
- } // TDragDropSession::DragSendDataProc
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::HandleEnterHandler
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragDropSession::HandleEnterHandler()
- {
- // initialize the flavor list
- fDragItemList->BuildListFromDrag();
-
- fDropTarget = NULL;
- fTargetWindow = NULL;
- fTargetIsHilited = FALSE;
- } // TDragDropSession::HandleEnterHandler
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::HandleLeaveHandler
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragDropSession::HandleLeaveHandler()
- {
- fDragItemList->FreeAll();
- } // TDragDropSession::HandleLeaveHandler
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::HandleEnterWindow
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragDropSession::HandleEnterWindow(TWindow* targetWindow)
- {
- if (gDispatcher->InModalState() && (gDispatcher->GetFrontWindow() != targetWindow))
- return;
-
- CDragItemIterator dragItemIterator(fDragItemList);
- targetWindow->DragEnteredWindow(dragItemIterator);
-
- fTargetWindow = targetWindow;
- } // TDragDropSession::HandleEnterWindow
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::HandleLeaveWindow
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragDropSession::HandleLeaveWindow()
- {
- this->SetDropTarget(NULL); // clear the current drop target
-
- if (fTargetWindow)
- {
- fTargetWindow->DragLeftWindow(); // notify the window
- fTargetWindow = NULL; // reset data
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::HandleTrackInWindow
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragDropSession::HandleTrackInWindow()
- {
- if (fTargetWindow && !this->HandleAutoScroll())
- {
- TView* newTarget;
- CPoint theMouse;
- CPoint pinnedMouse;
- VPoint localPoint;
-
- GetDragMouse(fDragReference, theMouse, pinnedMouse);
-
- CDragItemIterator dragItemIterator(fDragItemList);
- newTarget = fTargetWindow->MouseToDropTarget(dragItemIterator, pinnedMouse, localPoint);
-
- this->SetDropTarget(newTarget);
-
- if (fDropTarget)
- {
- fDropTarget->Focus();
- fDropTarget->DoDragWithin(localPoint);
- }
- }
- } // TDragDropSession::HandleTrackInWindow
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::HandleAutoScroll
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- Boolean TDragDropSession::HandleAutoScroll()
- {
- Boolean didScroll = FALSE;
-
- if (fScroller && (fTargetWindow == fSourceWindow)
- && fSourceWindow->IsActive() && fScroller->Focus())
- {
- VPoint delta;
- CPoint pinnedMouse;
- CPoint theMouse;
-
- GetDragMouse(fDragReference, theMouse, pinnedMouse);
- VPoint mouseInWindow(pinnedMouse);
- fSourceWindow->SuperToLocal(mouseInWindow);
-
- delta = fScroller->GetDragScrollDelta(mouseInWindow);
- if (delta != gZeroPt)
- {
- this->SetDropTarget(NULL); // clear the drop target
-
- fScroller->ScrollBy(delta, kRedraw); // scroll and inval
- fScroller->Update(); // redraw content
- didScroll = TRUE;
- }
- }
- return didScroll;
- } // TDragDropSession::HandleAutoScroll
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::HandleDragToTrash
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- Boolean TDragDropSession::HandleDragToTrash()
- {
- Boolean draggedToTrash = FALSE;
-
- if (!this->UserRequestedCopy() && this->IsDropLocationFinderTrash())
- {
- CDragItemIterator dragItemIterator(fDragItemList);
- TCommand *dragCommand = NULL;
-
- dragCommand = fDragSource->DoMakeDragDropCommand(cDrag, dragItemIterator);
- if (dragCommand)
- dragCommand->fContext->PostCommand(dragCommand);
-
- if (!gDispatcher->IsFrontProcess())
- gDispatcher->WakeProcess(); // time to wake up...
-
- draggedToTrash = TRUE;
- }
-
- return draggedToTrash;
- } // TDragDropSession::HandleDragToTrash
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::GetGlobalDragMouse
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragDropSession::GetGlobalDragMouse( CPoint& mouse,
- CPoint& pinnedMouse)
- {
- FailOSErr(GetDragMouse(fDragReference, mouse, pinnedMouse));
- } // TDragDropSession::GetGlobalDragMouse
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::SetGlobalPinnedDragMouse
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragDropSession::SetGlobalPinnedDragMouse(CPoint& pinnedMouse)
- {
- FailOSErr(SetDragMouse(fDragReference, pinnedMouse));
- } // TDragDropSession::SetGlobalPinnedDragMouse
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::SetDropTarget
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragDropSession::SetDropTarget(TView *newDropTarget)
- {
- // track whether drag has left the source view
- if (!fDragLeftSourceView && (newDropTarget != fDragSource))
- fDragLeftSourceView = TRUE;
-
- if (fDropTarget != newDropTarget)
- {
- if (fDropTarget)
- {
- fDropTarget->Focus();
- fDropTarget->DoDragLeave(); // resign the current target
- this->HideDropTargetHilite(); // unhilite the current target
- }
-
- fDropTarget = newDropTarget;
-
- if (fDropTarget)
- {
- fDropTarget->Focus();
- fDropTarget->DoDragEnter(); // target the new target
- this->ShowDropTargetHilite();
- }
- }
- } // TDragDropSession::SetDropTarget
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::RegisterDroppableWindow
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragDropSession::RegisterDroppableWindow(TWindow * theWindow,
- WindowRef theWindowMgrWindow)
- {
- // register a window with the Drag Manager.
-
- #if qDebug
- if (!HasDragManager())
- {
- ProgramBreak("Window tried to register w/DragSession when drag isn't available.");
- return;
- }
- #endif
-
- MAVolatileInit(WindowRef, volatileWindowMgrWindow, theWindowMgrWindow);
-
- FailInfo fi;
- Try(fi)
- {
- #if qContainer
- if (gContainerLib)
- {
- FailOSErr(CAInstallTrackingHandler(fDragTrackingHandlerUPP, theWindowMgrWindow, theWindow));
-
- FailOSErr(CAInstallReceiveHandler(fDragReceiveHandlerUPP, theWindowMgrWindow, theWindow));
- }
- else
- #endif
- {
- FailOSErr(InstallTrackingHandler(fDragTrackingHandlerUPP, theWindowMgrWindow,
- theWindow));
-
- FailOSErr(InstallReceiveHandler(fDragReceiveHandlerUPP, theWindowMgrWindow,
- theWindow));
- }
- fi.Success();
- }
- else // Recover
- {
- #if qContainer
- if (gContainerLib)
- {
- CARemoveTrackingHandler(fDragTrackingHandlerUPP, volatileWindowMgrWindow);
- CARemoveReceiveHandler(fDragReceiveHandlerUPP, volatileWindowMgrWindow);
- }
- else
- #endif
- {
- RemoveTrackingHandler(fDragTrackingHandlerUPP, volatileWindowMgrWindow);
- RemoveReceiveHandler(fDragReceiveHandlerUPP, volatileWindowMgrWindow);
- }
- }
- } // TDragDropSession::RegisterDroppableWindow
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::UnregisterDroppableWindow
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragDropSession::UnregisterDroppableWindow(WindowRef theWindowMgrWindow)
- {
- #if qDebug
- if (!HasDragManager())
- {
- ProgramBreak("Window tried to unregister w/DragSession when drag isn't available.");
- return;
- }
- #endif
-
- #if qContainer
- if (gContainerLib)
- {
- CARemoveTrackingHandler(fDragTrackingHandlerUPP, theWindowMgrWindow);
- CARemoveReceiveHandler(fDragReceiveHandlerUPP, theWindowMgrWindow);
- }
- else
- #endif
- {
- RemoveTrackingHandler(fDragTrackingHandlerUPP, theWindowMgrWindow);
- RemoveReceiveHandler(fDragReceiveHandlerUPP, theWindowMgrWindow);
- }
- } // TDragDropSession::UnregisterDroppableWindow
-
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::HasDragLeftSenderWindow
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- Boolean TDragDropSession::HasDragLeftSenderWindow() const
- {
- DragAttributes attributes;
-
- GetDragAttributes(fDragReference, &attributes);
- return ((attributes & dragHasLeftSenderWindow) == dragHasLeftSenderWindow);
- } // TDragDropSession::HasDragLeftSenderWindow
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::ShowDropTargetHilite
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragDropSession::ShowDropTargetHilite()
- {
- if (fDragLeftSourceView && fDropTarget)
- {
- RgnHandle hiliteRegion;
-
- hiliteRegion = fDropTarget->DoMakeDropHiliteRegion();
- fDropTarget->LocalToWindowRegion(hiliteRegion); // convert the region to window coords
- fTargetWindow->Focus();
-
- ShowDragHilite(fDragReference, hiliteRegion, TRUE);
- DisposeRgn(hiliteRegion);
- fTargetIsHilited = TRUE;
- }
- } // TDragDropSession::ShowDropTargetHilite
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::HideDropTargetHilite
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragDropSession::HideDropTargetHilite()
- {
- if (fTargetIsHilited)
- {
- fTargetWindow->Focus();
- HideDragHilite(fDragReference);
- fTargetIsHilited = FALSE;
- }
- } // TDragDropSession::HideDropTarget
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::GetItemCount
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- unsigned short TDragDropSession::GetItemCount()
- {
- return fDragItemList->GetSize();
- } // TDragDropSession::GetItemCount
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::UserIsDragging
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- Boolean TDragDropSession::UserIsDragging(CPoint& mousePoint)
- {
-
- return WaitMouseMoved(mousePoint);
- } // TDragDropSession::UserIsDragging
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::UserRequestedCopy
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- Boolean TDragDropSession::UserRequestedCopy()
- {
- if (!fUserRequestedCopy && IsOptionKeyDown())
- fUserRequestedCopy = TRUE;
-
- return fUserRequestedCopy;
- } // TDragDropSession::UserRequestedCopy
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::ClearDrag
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragDropSession::ClearDrag()
- {
- if (fDragReference)
- DisposeDrag(fDragReference);
-
- fDropTarget = NULL;
- fDragSource = NULL;
- fDragReference = 0;
- fScroller = NULL;
- fSourceWindow = NULL;
- fTargetWindow = NULL;
- fDragItemList->FreeAll();
- fDragReference = 0L;
- fDragLeftSourceView = FALSE;
- fTargetIsHilited = FALSE;
- fUserRequestedCopy = FALSE;
- } // TDragDropSession::ClearDrag
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::StartDrag
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragDropSession::StartDrag(TView* sourceView,
- TToolboxEvent* event,
- RgnHandle dragRegion)
- {
- OSErr dragErr;
- Boolean oldBusyCursorState;
-
- fDragSource = sourceView;
-
- this->UserRequestedCopy(); // test for copy override
- fScroller = fDragSource->GetScroller(FALSE);
- fSourceWindow = sourceView->GetWindow();
-
- oldBusyCursorState = gDispatcher->ActivateBusyCursor(FALSE);
-
- TUndoHandler::fgUndoHandler->BeginAction();
-
- #if qContainer
- if (gContainerLib)
- {
- // ••• I have no idea what the right CACloneKind is to use here
- // ••• It probably is not possible to determine it here
- // ••• We may need to save the CADocumentRef as a field of the drag session
-
- CADocumentRef caDoc = CAGetDragDropDocument(0);
- CADropResult dropResult = CAStartDrag(caDoc, &event->fEventRecords[0], dragRegion);
- if (event->fDoubleEvent)
- dropResult = CAStartDrag(caDoc, &event->fEventRecords[1], dragRegion);
- }
- else
- #endif
- dragErr = TrackDrag(fDragReference, &event->fEventRecord, dragRegion);
-
- // Must refocus on the source. Otherwise the port and the source
- // will get out of synch
- sourceView->Focus();
-
- if (dragErr == noErr)
- this->HandleDragToTrash();
-
- TUndoHandler::fgUndoHandler->EndAction();
-
- TInvalCursorCommand *cursorCommand = new TInvalCursorCommand;
- cursorCommand->IInvalCursorCommand();
- gDispatcher->PostCommand(cursorCommand);
-
- gDispatcher->ActivateBusyCursor(oldBusyCursorState);
-
- this->ClearDrag();
- } // TDragDropSession::StartDrag
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::AddDragItem
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- TDragItem* TDragDropSession::AddDragItem(ItemReference theItemRef)
- {
- if (fDragItemList->IsEmpty()) // create a new drag manager drag
- {
- FailOSErr(NewDrag(&fDragReference));
- #if qContainer
- if (gContainerLib)
- {
- // ••• I have no idea what the right CACloneKind is to use here
- // ••• It probably is not possible to determine it here
- // ••• We may need to save the CADocumentRef as a field of the drag session
-
- CADocumentRef caDoc = CAGetDragDropDocument(theItemRef);
-
- CASetDataSendProc(caDoc, fDragSendDataUPP, NULL);
- FailOSErr(CAError());
- }
- else
- #endif
- FailOSErr(SetDragSendProc(fDragReference, fDragSendDataUPP, NULL));
- }
-
- TDragItem *newItem = new TDragItem(theItemRef);
- newItem->IDragItem();
- fDragItemList->InsertElementInOrder(&newItem);
-
- return newItem;
- } // TDragDropSession::AddDragItem
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::GetDragItemByIndex
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- TDragItem* TDragDropSession::GetDragItemByIndex(unsigned short index)
- {
- TDragItem *indexedItem = (TDragItem *)fDragItemList->At(index);
- indexedItem->SetPosition(0);
- return indexedItem;
- } // TDragDropSession::GetDragItemByIndex
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::GetDragItemByReference
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- TDragItem* TDragDropSession::GetDragItemByReference(ItemReference itemReference)
- {
- TDragItem * dragItem = NULL;
- CDragItemIterator iter(fDragItemList);
-
- for (dragItem = iter.FirstDragItem(); iter.More(); dragItem = iter.NextDragItem())
- {
- if (dragItem->GetItemReference() == itemReference)
- {
- dragItem->SetPosition(0);
- return dragItem;
- }
- }
- Failure(minErr, 0);
- return NULL;
- } // TDragDropSession::GetDragItemByReference
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::GetDropLocationDescriptor
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragDropSession::GetDropLocationDescriptor(CAEDesc& dropLocationDesc) const
- {
- FailOSErr(GetDropLocation(fDragReference, dropLocationDesc));
- } // TDragDropSession::GetDropLocationDescriptor
-
- //----------------------------------------------------------------------------------------
- // TDragDropSession::IsDropLocationFinderTrash
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- Boolean TDragDropSession::IsDropLocationFinderTrash() const
- {
- MAVolatileInit(Boolean, result, FALSE);
-
- CTempDesc dropLocation;
-
- if (fDropTarget)
- return result;
-
- FailInfo fi;
- Try(fi)
- {
- FSSpec dropLocationSpec;
- CInfoPBRec cpb;
-
- this->GetDropLocationDescriptor(dropLocation);
-
- if (!dropLocation.CanCoerceDesc(typeFSS))
- result = FALSE;
- else
- {
- dropLocation.GetFSSpec(dropLocationSpec);
-
- cpb.dirInfo.ioNamePtr = dropLocationSpec.name; // get destination's info
- cpb.dirInfo.ioVRefNum = dropLocationSpec.vRefNum;
- cpb.dirInfo.ioFDirIndex = 0;
- cpb.dirInfo.ioDrDirID = dropLocationSpec.parID;
-
- FailOSErr(PBGetCatInfoSync(&cpb));
-
- if ((cpb.dirInfo.ioFlAttrib & (1<<4)) == (1<<4)) // it's a directory
- {
- short trashVRefNum;
- long trashDirID;
-
- FailOSErr(FindFolder(cpb.dirInfo.ioVRefNum,
- kTrashFolderType, kDontCreateFolder, &trashVRefNum, &trashDirID));
-
- if (cpb.dirInfo.ioDrDirID == trashDirID)
- result = TRUE;
- }
- }
- fi.Success();
- }
- else // recover
- {
- result = FALSE;
- }
-
- return result;
- } // TDragDropSession::IsDropLocationFinderTrash
-
- //========================================================================================
- // CLASS TDragItemList
- //========================================================================================
- #undef Inherited
- #define Inherited TList
-
- #pragma segment MADragNonRes
- MA_DEFINE_CLASS_M1(TDragItemList, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TDragItemList::TDragItemList
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- TDragItemList::TDragItemList()
- {
-
- } // TDragItemList::TDragItemList
-
- //----------------------------------------------------------------------------------------
- // TDragItemList::~TDragItemList
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- TDragItemList::~TDragItemList()
- {
-
- } // TDragItemList::~TDragItemList
-
- //----------------------------------------------------------------------------------------
- // TDragItemList::IDragItemList
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragItemList::IDragItemList()
- {
- this->IList();
- } // TDragItemList::IDragItemList
-
- //----------------------------------------------------------------------------------------
- // TDragItemList::BuildListFromDrag
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragItemList::BuildListFromDrag()
- {
- DragReference dragReference = TDragDropSession::fgDragDropSession->GetDragReference();
- unsigned short itemCount;
- TDragItem* dragItem;
- ItemReference itemReference;
-
- this->FreeAll();
-
- FailOSErr(CountDragItems(dragReference, &itemCount));
-
- for (unsigned short itemIndex = 1; itemIndex <= itemCount; itemIndex++)
- {
- FailOSErr(GetDragItemReferenceNumber(dragReference, itemIndex, &itemReference));
- dragItem = new TDragItem(itemReference);
- dragItem->IDragItem();
- this->InsertElementsBefore(fSize + 1, &dragItem, 1);
- }
- } // TDragItemList::BuildListFromDrag
-
- //========================================================================================
- // CLASS TDragItem
- //========================================================================================
- #undef Inherited
- #define Inherited TObject
-
- #pragma segment MADragNonRes
- MA_DEFINE_CLASS_M1(TDragItem, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TDragItem::TDragItem : Empty constructor here to make the compiler happy. Callers
- // should use the alternate constructor that takes an ItemReference as an argument.
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- TDragItem::TDragItem()
- : fItemReference(0),
- fFlavorOffset(0),
- fFlavorType('\?\?\?\?')
- {
-
- } // TDragItem::TDragItem
-
- //----------------------------------------------------------------------------------------
- // TDragItem::TDragItem
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- TDragItem::TDragItem(ItemReference itemReference)
- : fItemReference(itemReference),
- fFlavorOffset(0),
- fFlavorType('\?\?\?\?')
- {
-
- } // TDragItem::TDragItem
-
- //----------------------------------------------------------------------------------------
- // TDragItem::~TDragItem
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- TDragItem::~TDragItem()
- {
-
- } // TDragItem::~TDragItem
-
- //----------------------------------------------------------------------------------------
- // TDragItem::IDragItem
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragItem::IDragItem()
- {
- this->IObject();
- } // TDragItem::IDragItem
-
- //----------------------------------------------------------------------------------------
- // TDragItem::AddFlavor
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragItem::AddFlavor( FlavorType newFlavor,
- CFlavorFlags& flavorFlags,
- void* buffer,
- long count)
- {
- FailOSErr(AddDragItemFlavor(TDragDropSession::fgDragDropSession->GetDragReference(), fItemReference,
- newFlavor, buffer, count, flavorFlags));
- this->FocusOnFlavor(newFlavor);
- fFlavorOffset = count;
- } // TDragItem::AddFlavor
-
- //----------------------------------------------------------------------------------------
- // TDragItem::PromiseFlavor
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragItem::PromiseFlavor( FlavorType newFlavor,
- CFlavorFlags& flavorFlags)
- {
- FailOSErr(AddDragItemFlavor(TDragDropSession::fgDragDropSession->GetDragReference(), fItemReference,
- newFlavor, NULL, 0L, flavorFlags));
- this->FocusOnFlavor(newFlavor);
- } // TDragItem::PromiseFlavor
-
- //----------------------------------------------------------------------------------------
- // TDragItem::CountFlavors
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- unsigned short TDragItem::CountFlavors()
- {
- unsigned short flavorCount;
-
- FailOSErr(CountDragItemFlavors(TDragDropSession::fgDragDropSession->GetDragReference(),
- fItemReference, &flavorCount));
-
- return flavorCount;
- } // TDragItem::CountFlavors
-
- //----------------------------------------------------------------------------------------
- // TDragItem::FlavorExists
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- Boolean TDragItem::FlavorExists(FlavorType requestedFlavor)
- {
- FlavorFlags flags;
-
- if (GetFlavorFlags(TDragDropSession::fgDragDropSession->GetDragReference(), fItemReference,
- requestedFlavor, &flags) == noErr)
- return TRUE;
- else
- return FALSE;
- } // TDragItem::FlavorExists
-
- //----------------------------------------------------------------------------------------
- // TDragItem::FocusOnFlavor
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragItem::FocusOnFlavor(FlavorType focusFlavor)
- {
- fFlavorOffset = 0;
-
- if (this->FlavorExists(focusFlavor))
- fFlavorType = focusFlavor;
- else
- FailOSErr(badDragFlavorErr);
- } // TDragItem::FocusOnFlavor
-
- //----------------------------------------------------------------------------------------
- // TDragItem::GetPosition
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- long TDragItem::GetPosition()
- {
- return fFlavorOffset;
- } // TDragItem::GetPosition
-
- //----------------------------------------------------------------------------------------
- // TDragItem::SetPosition
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragItem::SetPosition(long newPosition)
- {
- fFlavorOffset = newPosition;
- } // TDragItem::SetPosition
-
- //----------------------------------------------------------------------------------------
- // TDragItem::GetBounds
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- CRect TDragItem::GetBounds()
- {
- CRect itemBounds;
-
- FailOSErr(GetDragItemBounds(TDragDropSession::fgDragDropSession->GetDragReference(),
- fItemReference, itemBounds));
-
- return itemBounds;
- } // TDragItem::GetBounds
-
- //----------------------------------------------------------------------------------------
- // TDragItem::SetBounds
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragItem::SetBounds(CRect& itemBounds)
- {
- if (itemBounds != gZeroRect)
- FailOSErr(SetDragItemBounds(TDragDropSession::fgDragDropSession->GetDragReference(),
- fItemReference, itemBounds));
- } // TDragItem::SetBounds
-
- //----------------------------------------------------------------------------------------
- // TDragItem::GetSize
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- long TDragItem::GetSize()
- {
- long dataSize;
-
- FailOSErr(GetFlavorDataSize(TDragDropSession::fgDragDropSession->GetDragReference(),
- fItemReference, fFlavorType, &dataSize));
-
- return dataSize;
- } // TDragItem::GetSize
-
- //----------------------------------------------------------------------------------------
- // TDragItem::GetFlags
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- CFlavorFlags TDragItem::GetFlags()
- {
- CFlavorFlags flags;
-
- FailOSErr(GetFlavorFlags(TDragDropSession::fgDragDropSession->GetDragReference(), fItemReference,
- fFlavorType, flags));
-
- return flags;
- } // TDragItem::GetFlags
-
- //----------------------------------------------------------------------------------------
- // TDragItem::GetFlavorType
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- FlavorType TDragItem::GetFlavorType()
- {
- return fFlavorType;
- } // TDragItem::GetFlavorType
-
- //----------------------------------------------------------------------------------------
- // TDragItem::GetData
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragItem::GetData(void* buffer,
- long& count)
- {
- FailOSErr(GetFlavorData(TDragDropSession::fgDragDropSession->GetDragReference(), fItemReference,
- fFlavorType, buffer, &count, fFlavorOffset));
- fFlavorOffset += count;
- } // TDragItem::GetData
-
- //----------------------------------------------------------------------------------------
- // TDragItem::GetDataAsHandle
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- Handle TDragItem::GetDataAsHandle()
- {
- Handle dataHandle = NULL;
-
- TDragFlavorStream *dragFlavorStream = new TDragFlavorStream;
- dragFlavorStream->IDragFlavorStream(fFlavorType, fItemReference);
- dragFlavorStream->SetPosition(fFlavorOffset);
- dataHandle = StreamToHandle(dragFlavorStream);
- fFlavorOffset = dragFlavorStream->GetPosition();
- FreeIfObject(dragFlavorStream);
-
- return dataHandle;
- } // TDragItem::GetDataAsHandle
-
- //----------------------------------------------------------------------------------------
- // TDragItem::SetData
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragItem::SetData(void * buffer,
- long count)
- {
- FailOSErr(SetDragItemFlavorData(TDragDropSession::fgDragDropSession->GetDragReference(), fItemReference,
- fFlavorType, buffer, count, fFlavorOffset));
- fFlavorOffset += count;
- } // TDragItem::SetData
-
- //----------------------------------------------------------------------------------------
- // TDragItem::SetDataFromHandle
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragItem::SetDataFromHandle(Handle dataHandle)
- {
- if (!dataHandle)
- Failure(minErr, 0);
-
- MAVolatileInit(SignedByte, savedHandleState, LockHandle(dataHandle));
-
- FailInfo fi;
- Try(fi)
- {
- Size dataSize = GetHandleSize(dataHandle);
- FailMemError();
-
- this->SetData(*dataHandle, dataSize);
- HSetState(dataHandle, savedHandleState);
- fi.Success();
- }
- else // Recover
- {
- HSetState(dataHandle, savedHandleState);
- fi.ReSignal();
- }
- } // TDragItem::SetDataFromHandle
-
- //----------------------------------------------------------------------------------------
- // TDragItem::GetDataStream
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- TDragFlavorStream* TDragItem::GetDataStream()
- {
- TDragFlavorStream *flavorStream = new TDragFlavorStream;
- flavorStream->IDragFlavorStream(fFlavorType, fItemReference);
-
- return flavorStream;
- } // TDragFlavorStream::GetDataStream
-
-
- //========================================================================================
- // CLASS TDragFlavorStream
- //========================================================================================
- #undef Inherited
- #define Inherited TStream
-
- #pragma segment MADragNonRes
- MA_DEFINE_CLASS_M1(TDragFlavorStream, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TDragFlavorStream::TDragFlavorStream
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- TDragFlavorStream::TDragFlavorStream()
- : fPosition(0),
- fFlavorType('\?\?\?\?'),
- fItemReference(0)
- {
- #if qDebug
- fInstanceCount++; // increment the instance counter
- #endif
- } // TDragFlavorStream::TDragFlavorStream
-
- //----------------------------------------------------------------------------------------
- // TDragFlavorStream::IDragFlavorStream:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragFlavorStream::IDragFlavorStream(FlavorType theFlavor,
- ItemReference theReference)
- {
- fFlavorType = theFlavor;
- fItemReference = theReference;
-
- this->IStream();
- } // TDragFlavorStream::IDragFlavorStream
-
-
- //----------------------------------------------------------------------------------------
- // TDragFlavorStream::~TDragFlavorStream
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- TDragFlavorStream::~TDragFlavorStream()
- {
- #if qDebug
- fInstanceCount--; // decrement the instance counter
- #endif
- } // TDragFlavorStream::~TDragFlavorStream
-
-
- #if qDebug
- //----------------------------------------------------------------------------------------
- // TDragFlavorStream::CheckReferenceCount
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragFlavorStream::CheckInstanceCount()
- {
- // This method is called by TDragSession before returning control to the drag manager
- // after receiving a drop. Any existing instances of TDragFlavorStream are about to
- // become invalid. If a positive instance count exists, a program break is
- // generated.
- if (fInstanceCount)
- {
- ProgramBreak("###TDragFlavorStream failed instance count check");
- fInstanceCount = 0; // reset the count
- }
- } // TDragFlavorStream::CheckReferenceCount
- #endif // qDebug
-
-
- //----------------------------------------------------------------------------------------
- // TDragFlavorStream::GetPosition
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- long TDragFlavorStream::GetPosition()
- {
- return fPosition;
- } // TDragFlavorStream::GetPosition
-
- //----------------------------------------------------------------------------------------
- // TDragFlavorStream::SetPosition
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragFlavorStream::SetPosition(long newPosition)
- {
- OSErr err = noErr;
- long dataSize;
-
- dataSize = this->GetSize();
-
- if (newPosition < 0) // Same error returned by File Manager
- FailOSErr(posErr);
- else if (newPosition > dataSize) // Hit the end of the stream
- {
- newPosition = dataSize; // Position to end of stream
- err = eofErr;
- }
-
- fPosition = newPosition;
- FailOSErr(err);
- } // TDragFlavorStream::SetPosition
-
- //----------------------------------------------------------------------------------------
- // TDragFlavorStream::GetSize
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- long TDragFlavorStream::GetSize()
- {
- long dataSize;
- OSErr err;
-
- err = GetFlavorDataSize(TDragDropSession::fgDragDropSession->GetDragReference(), fItemReference,
- fFlavorType, &dataSize);
- if (err != noErr)
- dataSize = 0L;
-
- return dataSize;
- } // TDragFlavorStream::GetSize
-
- //----------------------------------------------------------------------------------------
- // TDragFlavorStream::ReadBytes
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragFlavorStream::ReadBytes(void* p,
- long count)
- {
- if (count < 0)
- FailOSErr(paramErr); // Negative count request
-
- if (this->GetSize() - fPosition < count)
- FailOSErr(eofErr); // about to read past end of stream
-
- // read the bytes
- long bytesRead = count;
- FailOSErr(GetFlavorData(TDragDropSession::fgDragDropSession->GetDragReference(), fItemReference,
- fFlavorType, p, &bytesRead, fPosition));
- fPosition += bytesRead;
- } // TDragFlavorStream::ReadBytes
-
- //----------------------------------------------------------------------------------------
- // TDragFlavorStream::WriteBytes
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TDragFlavorStream::WriteBytes(const void* p,
- long count)
- {
- FailOSErr(SetDragItemFlavorData(TDragDropSession::fgDragDropSession->GetDragReference(), fItemReference,
- fFlavorType, p, count, fPosition));
- fPosition += count;
- } // TDragFlavorStream::WriteBytes
-
- //========================================================================================
- // CLASS CDragItemIterator
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CDragItemIterator::CDragItemIterator
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- CDragItemIterator::CDragItemIterator(TDragItemList* itsDragItemList,
- Boolean itsForward)
- : CArrayIterator(itsDragItemList, itsForward)
- {
-
- } // CDragItemIterator::CDragItemIterator
-
- //----------------------------------------------------------------------------------------
- // CDragItemIterator destructor
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- CDragItemIterator::~CDragItemIterator()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CDragItemIterator::CurrentDragItem
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- TDragItem* CDragItemIterator::CurrentDragItem()
- {
- if (this->More())
- return (TDragItem *)((TDragItemList *)fDynamicArray)->At(fCurrentIndex);
- else
- return NULL;
- } // CDragItemIterator::CurrentDragItem
-
- //----------------------------------------------------------------------------------------
- // CDragItemIterator::FirstDragItem
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- TDragItem* CDragItemIterator::FirstDragItem()
- {
- this->Reset();
- if (this->More())
- return (TDragItem *)((TDragItemList *)fDynamicArray)->At(fCurrentIndex);
- else
- return NULL;
- } // CDragItemIterator::FirstDragItem
-
- //----------------------------------------------------------------------------------------
- // CDragItemIterator::NextDragItem
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- TDragItem* CDragItemIterator::NextDragItem()
- {
- this->Advance();
- if (this->More())
- return (TDragItem *)((TDragItemList *)fDynamicArray)->At(fCurrentIndex);
- else
- return NULL;
- } // CDragItemIterator::NextDragItem
-
- //========================================================================================
- // CLASS TInvalCursorCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TCommand
-
- #pragma segment MACommandNonRes
- MA_DEFINE_CLASS_M1(TInvalCursorCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TInvalCursorCommand::TInvalCursorCommand
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- TInvalCursorCommand::TInvalCursorCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TInvalCursorCommand::IInvalCursorCommand
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- void TInvalCursorCommand::IInvalCursorCommand()
- {
- this->ICommand(cNoCommand, NULL, kCantUndo, kDoesNotCauseChange, NULL);
- }
-
- //----------------------------------------------------------------------------------------
- // TInvalCursorCommand::DoIt
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- void TInvalCursorCommand::DoIt()
- {
- // Compute based on where the mouse is right now
- CPoint globalMouse;
-
- GetMouse(globalMouse);
- LocalToGlobal(globalMouse);
-
- gDispatcher->UpdateAllWindows(); // necessary for calculation of visible regions
- gDispatcher->InvalidateMouseRegions();
- gDispatcher->TrackCursor(globalMouse);
- }
-
- #endif // qDrag
-
- //----------------------------------------------------------------------------------------
- // End of UDragDrop.cp
-
- #pragma segment Inline
-